package com.sping_boot3.spirng_boot3.juc;

import lombok.Data;

import java.util.concurrent.locks.ReentrantLock;

@Data
public class Ticket_Lock {
    ReentrantLock lock = new ReentrantLock();
    private int number = 10;

    public void sale() {

        try {
            lock.lock();
            if (number > 0) {
                number--;
                System.out.println(Thread.currentThread() + "买出一张:" + "剩余" + number);
            }
        } finally {
            lock.unlock();
        }
    }
}
